package userServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.cj.jdbc.ha.BalanceStrategy;

import userDao.UserDao;
import userEntity.User;
import userImplment.UserImplement;

/**
 * Servlet implementation class Reset
 */
public class Reset extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Reset() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String Uname = request.getParameter("Uname");
		String idType = request.getParameter("idType");
		String idCard = request.getParameter("idCard");
		String phone = request.getParameter("phone");
		HttpSession session = request.getSession();
		PrintWriter out=response.getWriter();
		UserDao userImplement=new UserImplement();
		User user=new User();
		if(session.getAttribute("user")!=null){
				user.setId( ((User)session.getAttribute("user")).getId());
				user.setUname(Uname);
				user.setPassWord( ((User)session.getAttribute("user")).getPassWord());
				user.setIdType(idType);
				user.setIdCard(idCard);
				user.setPhone(phone);
				user.setBalance( ((User)session.getAttribute("user")).getBalance());
				if(userImplement.Reset(user,user.getId()) ){
					//修改成功，保存用户信息到session，并跳转到到查看个人信息页面
					session.setAttribute("user", user);
					out.write("true");

				}else {
					//修改失败跳转到错误提示页面

					out.write("false");
				}
		}else {
			out.write("null");
		}

		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
